<template>
	<view>
		<view class="uni-padding-wrap uni-common-mt">
			<!-- <view class="uni-hello-text">
				<br>
			</view> -->
			<view class="uni-title uni-common-mt">
				<uni-icons type="star-filled" size="15"></uni-icons>

				<!-- flex-direction: column -->
				星标项目
				<br>
				<text class="">project list</text>
				<view class="uni-flex uni-column">
					<view v-for="(item,index) in project_list.star" @tap="toDashboard(item.value.id)"
						class="flex-item flex-item-V uni-border" :style="{background:item.value.color_display}">
						{{item.value.name}}
					</view>
					<!-- 切换到了switchTab -->
					<!-- <navigator v-for="(item,index) in project_list.star"
						:url="routes['dashboard']+'?project_id='+encodeURIComponent(item.value.id)"
						hover-class="navigator-hover">
						<view class="flex-item flex-item-V uni-border" :style="{background:item.value.color_display}">
						{{item.value.name}}
						</view>
					</navigator> -->
				</view>
			</view>


			<view class="uni-title uni-common-mt">
				<!-- flex-direction: column -->
				<uni-icons type="list" size="15"></uni-icons>
				我创建的项目
				<br>
				<text>project list</text>
				<view class="uni-flex uni-column">
					<view v-for="(item,index) in project_list.my" @tap="toDashboard(item.id)"
						class="flex-item flex-item-V uni-border" :style="{background:item.color_display}">
						{{item.name}}
					</view>
					<!-- <navigator v-for="(item,index) in project_list.my"
						:url="routes['dashboard']+'?project_id='+encodeURIComponent(item.id)"
						hover-class="navigator-hover">
						<view class="flex-item flex-item-V uni-border" :style="{background:item.color_display}">
						{{item.name}}
						</view>
					</navigator> -->
				</view>
			</view>

			<view class="uni-flex uni-column">
			</view>

			<view class="uni-title uni-common-mt">
				<!-- flex-direction: column -->
				<uni-icons type="staff-filled" size="15"></uni-icons>

				我参与的项目
				<br>
				<text>project list</text>
				<view class="uni-flex uni-column">
					<view v-for="(item,index) in project_list.join" @tap="toDashboard(item.id)"
						class="flex-item flex-item-V uni-border" :style="{background:item.color_display}">
						{{item.name}}
					</view>
					<!-- <navigator v-for="(item,index) in project_list.join"
						:url="routes['dashboard']+'?project_id='+encodeURIComponent(item.id)"
						hover-class="navigator-hover">
						<view class="flex-item flex-item-V uni-border" :style="{background:item.color_display}">
						{{item.name}}
						</view>
					</navigator> -->

				</view>
			</view>


			<view class="uni-title uni-common-mt">
			</view>

		</view>
	</view>
</template>
<script>
	import {
		apis,
		routes
	} from '@/common/paths.js'
	export default {
		data() {
			return {
				user_token: uni.getStorageSync('user_token'),
				project_list: [],
				routes: routes
			}
		},
		methods: {
			// setStyle(color_display){
			// 	console.log(color_display);
			// 	return 'background:'+color_display
			// }
			toDashboard(project_id) {
				uni.navigateTo({
					url: routes['dashboard'] + '?project_id=' + project_id,
				})
			},
			doProjectList() {
				uni.request({
					url: this.backendServer + apis['do_project_list'],
					method: 'get',
					// dataType:'application/json',
					data: {
						'user_id': this.user_token
					},
					success: (res) => {
						uni.hideLoading()
						console.log('success res ', res)
						if (res.data.status) {
							console.log('request ok')

							this.project_list = res.data.project_list
							console.log("project_list: " + JSON.stringify(this.project_list));
						} else {
							uni.showToast({
								title: "获取失败，请检查用户名或密码",
								icon: 'fail'
							})
							uni.switchTab({
								url: routes['index']
							})
							// this.project_list = []
						}
					},
					fail: (res) => {
						uni.hideLoading()
						console.log('fail res ', res)
						uni.showToast({
							title: "获取失败，请检查网络联接",
							icon: 'fail'
						})
						uni.switchTab({
							url: routes['index']
						})
						// this.project_list = []
					}
				})
			}
		},
		onLoad() {
			//done 已经通过common/interceptor.js进行了拦截
			// if (!this.user_token) {
			// 	uni.redirectTo({
			// 		url: routes['login']
			// 	})
			// } else {
				uni.startPullDownRefresh({
					success() {
					},
					complete() {
						console.log('startPullDownRefresh complete');
					}
				})
			// }

		},
		onPullDownRefresh() {
			console.log('refresh');
			this.doProjectList()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		}
	}
</script>

<style>
	@import url("index.css");
</style>